package com.boboPlanet.user.filter;

import com.boboPlanet.comm.thread.ThreadMdcUtil;
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
import org.slf4j.MDC;

import java.util.concurrent.Callable;

/**
 * @Description: TODO 解决feign调用时MDC获取不到问题
 * @Author: mis_wu
 * @Date: 2023/5/7
 * @Company xxx
 **/
public class RequestContextHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy {

    @Override
    public <T> Callable<T> wrapCallable(final Callable<T> callable) {
        // 使用阿里的 TtlCallable 重新包一层，解决线程间数据传递问题
        // return TtlCallable.get(callable);
        // 使用自定义的包装对象，将当前mdc复制到Hystrix新线程中
        return ThreadMdcUtil.wrap(callable, MDC.getCopyOfContextMap());
    }

}
